/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cl.zeke.remoto.vista.controllers;

import cl.zeke.comun.dto.Persona;
import cl.zeke.remoto.negocio.services.ComunesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @author taller
 */
@Controller
@RequestMapping("/restful/persona")
public class PersonaController {

    private static Logger log = LoggerFactory.getLogger(PersonaController.class);

    @Autowired
    private ComunesService comunesService;

    @RequestMapping(value = "/{nombre}", method = RequestMethod.GET)
    public @ResponseBody
    Persona traerPersona(@PathVariable("nombre") String nombre) {
        return comunesService.traerPersona(nombre);
    }

    @RequestMapping(method = RequestMethod.POST)
    public @ResponseBody Boolean guardarPersona(@RequestBody Persona p) {
        try {
            log.info("guardando");
            log.info("p: " + p.getNombre() + " " + p.getEdad());
            for (Persona f : p.getFamiliares()) {
                log.info("f: " + f.getNombre() + " " + f.getEdad());
            }
            return true;
        } catch (Exception ex) {
            return false;
        }
    }

}
